/*
 * @Author: sunkai@xinxinapp.cn
 * @Date: 2020-06-11 13:06:02
 * @LastEditTime: 2020-12-20 15:51:54
 * @LastEditors: sunkai@xinxinapp.cn
 * @Description: 
 * @FilePath: /fed-e-task-02-02/webpack.common.js
 */

const webpack = require('webpack')

const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')

const VueLoaderPlugin = require('vue-loader/lib/plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

/**
 * @type {import('webpack').Configuration}
 */
module.exports = {
  entry: './src/main.js',
  // output: './dist/main.js',
  output: {
    filename: '[name]-[contenthash:8].bundle.js',
    path: path.join(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['@babel/preset-env'] 
            ] 
          }
        }
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.(less|css)$/,
        use: ['style-loader', 'css-loader', 'less-loader']
      },
      {
        test: /\.(png|jpe?j|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10 * 1024,
          name: 'img/[name].[ext]?[hash]'
        }
      },
      {
        test: /\.html$/,
        use: 'html-loader'
      },
    ]
  },
  plugins: [
    new webpack.DefinePlugin({
      BASE_URL: '"public/"'
    }),
    new HtmlWebpackPlugin({
      title: 'webpack',
      template: './public/index.html'
    }),
    new VueLoaderPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        { from: './src/assets', to: 'assets' }
      ],
      options: {
        concurrency: 100,
      }
    })
  ]
}